/**
 * Panel d'accueuil
 * 
 * @author Marie-Hélène Goddet, Damien Finck, Cédric Schaller
 * 
 */
package gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class JHome extends JPanel {
	
	private ActionListener actionListener;
	
	protected Component horizontalStrut_1,horizontalStrut_2;
	protected Component verticalStrut_1,verticalStrut_2;
	protected JPanel jp_center;
		protected JButton jb_write;
		protected JButton jb_inbox;
		protected JButton jb_sendbox;
		protected JButton jb_drafts;
	
	/**
	 * Constructeur
	 */
	public JHome() {
		/** Evénements **/
		ActionListener action = new Event_JPHome(this);
		/** Création des éléments     **/
		this.verticalStrut_1 = Box.createVerticalStrut(50);
		this.horizontalStrut_1 = Box.createHorizontalStrut(50);
		this.horizontalStrut_2 = Box.createHorizontalStrut(50);
		this.verticalStrut_2 = Box.createVerticalStrut(50);
		this.jp_center = new JPanel(new GridLayout(4,1));
			this.jb_write = new JButton("Ecrire un message");
			this.jb_inbox = new JButton("Boite de reception");
			this.jb_sendbox = new JButton("Boite d'envoi");
			this.jb_drafts = new JButton("Brouillons");
		/** Paramétrage des éléments  **/
		Font f1 = new Font("Default",Font.BOLD,18);
		this.jb_write.setFont(f1);
		this.jb_inbox.setFont(f1);
		this.jb_sendbox.setFont(f1);
		this.jb_drafts.setFont(f1);
		this.jb_inbox.setEnabled(false);
		this.jb_sendbox.setEnabled(false);
		this.jb_drafts.setEnabled(false);
		this.setLayout(new BorderLayout());
		/** Action sur les éléments   **/
		this.jb_write.addActionListener(action);
		/** Montage des éléments      **/
		this.add(this.verticalStrut_1,BorderLayout.NORTH);
		this.add(this.horizontalStrut_1,BorderLayout.WEST);
		this.add(this.jp_center,BorderLayout.CENTER);
			this.jp_center.add(this.jb_write);
			this.jp_center.add(this.jb_inbox);
			this.jp_center.add(this.jb_sendbox);
			this.jp_center.add(this.jb_drafts);
		this.add(this.horizontalStrut_2,BorderLayout.EAST);
		this.add(this.verticalStrut_2,BorderLayout.SOUTH);
	}
	public void addActionListener(ActionListener actionListener) {
		this.actionListener = actionListener;
	}
	public ActionListener getActionListener() {
		return actionListener;
	}
}
class Event_JPHome implements ActionListener {
	JHome jp;
	/**
	 * Constructeur
	 * @param jp le panel d'acceuil
	 */
	public Event_JPHome(JHome jp) {
		this.jp=jp;
	}
	/**
	 * Appelée lors de l'appui sur une touche de l'accueuil
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		Object obj = arg0.getSource();
		if (obj instanceof JButton) {
			JButton jb = (JButton)obj;
			if (jb==jp.jb_write) {
				ActionEvent e = new ActionEvent(jp,1001,"JPHome_done");
				jp.getActionListener().actionPerformed(e);
			}
		}
	}
}